home *** CD-ROM | disk | FTP | other *** search
/ Complete Linux / Complete Linux.iso / docs / apps / database / postgres / postgre1.z / postgre1 / test / postfs / loadfilei.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-27  |  871 b   |  41 lines

  1. /* usage: loadfile unix-path postfs-path bufsize(in bytes) */
  2. #include <sys/file.h>
  3. #include "tmp/libpq-fs.h"
  4. #include "catalog/pg_lobj.h"
  5. void main(ac,av)
  6.      int ac;
  7.      char *av[];
  8. {
  9.     int fd, pfd;
  10.     int n, pn;
  11.     int blen = 65536;
  12.     char *buf;
  13.     char *res;
  14.  
  15.     PQsetdb(getenv("USER"));
  16.     if (ac != 3) {
  17.     printf ("usage: %s unix-path postfs-path\n",av[0]);
  18.     exit(1);
  19.     }
  20.  
  21.     res = PQexec("begin");
  22. /*    blen = atoi(av[3]);*/
  23.     buf = (char *)malloc(blen);
  24.     if (p_open(av[2],O_RDONLY) < 0) {
  25.     fd = open(av[1],O_RDONLY);
  26.     pfd = p_creat(av[2],0 /*DEFAULT_SMGR*/,Inversion);
  27.     while ((n = read(fd,buf,blen)) > 0) {
  28.         if ((pn = p_write(pfd,buf,n)) != n) {
  29.         }
  30. /*        printf ("p_write returned %d\n",pn);*/
  31.     }
  32.     close(fd);
  33.     p_close(pfd);
  34.     } else {
  35.     printf ("file already exists\n");
  36.     }
  37.     res = PQexec("end");
  38.     PQfinish();
  39.     exit(0);
  40. }
  41.